﻿using Infrastructure.Attribute;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZR.Model.Dto.Business.ProductionControl;
using ZR.Model;
using ZR.Model.Models.ProductionControl;
using ZR.Repository;
using ZR.Service.IService.ProductionControl;
using ZR.ServiceCore.Services;

namespace ZR.Service.Service.ProductionControl
{
    [AppService(ServiceType = typeof(IScannerConfigService), ServiceLifetime = LifeTime.Transient)]
    public class ScannerConfigService : BaseService<ScannerConfig>, IScannerConfigService
    {
        /// <summary>
        /// 查询扫码枪配置表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public PagedInfo<ScannerConfigDto> GetList(ScannerConfigQueryDto parm)
        {
            var predicate = QueryExp(parm);

            var response = Queryable()
                .Where(predicate.ToExpression())
                .ToPage<ScannerConfig, ScannerConfigDto>(parm);

            return response;
        }

        /// <summary>
        /// 获取详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public ScannerConfig GetInfo(int Id)
        {
            var response = Queryable()
                .Where(x => x.Id == Id)
                .First();

            return response;
        }

        /// <summary>
        /// 添加扫码枪配置表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ScannerConfig AddScannerConfig(ScannerConfig model)
        {
            return Insertable(model).ExecuteReturnEntity();
        }

        /// <summary>
        /// 修改扫码枪配置表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int UpdateScannerConfig(ScannerConfig model)
        {
            return Update(model, true);
        }

        /// <summary>
        /// 查询导出表达式
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        private static Expressionable<ScannerConfig> QueryExp(ScannerConfigQueryDto parm)
        {
            var predicate = Expressionable.Create<ScannerConfig>();

            return predicate;
        }

        public List<ScannerConfig> QueryByStationCode(string[] code)
        {
            return Queryable().Where(w => code.Contains(w.WorkstationCode)).ToList();
        }
    }
}